package com.fdl.action.security;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;

import com.fdl.common.utils.RandomNumUtil;
import com.opensymphony.xwork2.ActionContext;

/**
 * 验证码生成器
 * @project: hb-intra
 * @Date:2010-8-4
 * @version 1.0
 * @Company: 33e9
 * @author zhangYong.huang
 */

public class RenderImageCaptchaAction {

	/**
	 * 
	 * 验证码生成
	 * @return
	 * @throws Exception
	 */
	public String generate() throws Exception {
		HttpServletResponse httpServletResponse = ServletActionContext.getResponse();
		RandomNumUtil rdnu=RandomNumUtil.Instance();    
		//取得随机字符串放入HttpSession
		ActionContext.getContext().getSession().put("random", rdnu.getString());

		httpServletResponse.setHeader("Cache-Control", "no-store");
		httpServletResponse.setHeader("Pragma", "no-cache");
		httpServletResponse.setDateHeader("Expires", 0L);
		httpServletResponse.setContentType("image/jpeg");
		ServletOutputStream responseOutputStream = httpServletResponse
				.getOutputStream();
		responseOutputStream.write(rdnu.getImage().toByteArray());//取得带有随机字符串的图片    
		responseOutputStream.flush();
		responseOutputStream.close();
		return null;
	}

	
}
